package demo2;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: liangyuanzhang
 * Date: 2025-3-08
 * Time: 13:55
 */
class Login{
    private String userNume;
    private String passWord;

    public String getUserNume() {
        return userNume;
    }

    public void setUserNume(String userNume) {
        this.userNume = userNume;
    }

    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }

    public void logInfo(String userNume,String passWord){
        if (!this.userNume.equals(userNume)){
            throw new UserNameException("用户名错误异常...");
        }
        if (!this.passWord.equals(passWord)){
            throw new passWordException("密码错误异常...");
        }
        System.out.println("登录成功!");
    }

}

public class Test {
    public static void main(String[] args) {
        Login login = new Login();
        login.setUserNume("admin");
        login.setPassWord("admin");

        Scanner scanner = new Scanner(System.in);

        try {
            System.out.print("请输入用户名:");
            String username = scanner.nextLine();
            System.out.print("请输入密码:");
            String password = scanner.nextLine();
            login.logInfo(username,password);
        }catch (UserNameException e){
            e.printStackTrace();
        }catch (passWordException e){
            e.printStackTrace();
        }finally {

        }
    }
}
